package cn.itsource.redis.common.controller;

import cn.itsource.common.StaticPageClient;
import cn.itsource.util.AjaxResult;
import cn.itsource.util.VelocityUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
public class StaticPageController implements StaticPageClient {
    @PostMapping("/geneStaticPage")
    public AjaxResult geneStaticPage(@RequestBody Map<String,Object> map){
        /*模版路径*/
        String templatePathAndName = (String) map.get("templatePathAndName");
        /*生成路径*/
        String targetPathAndName = (String) map.get("targetPathAndName");
        /*数据？
        * */
        Object model = map.get("model"); ;

        try {
            VelocityUtils.staticByTemplate(model,templatePathAndName,targetPathAndName);
            return  AjaxResult.me().setSuccess(true).setMessage("静态化成功");
        } catch (Exception e) {
            e.printStackTrace();
            return  AjaxResult.me().setSuccess(false).setMessage("静态化失败"+e.getMessage());
        }
    }
}
